package Test9;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyUtil {
    public static Star createProxy(BigStar bigStar){
        Star star=(Star) Proxy.newProxyInstance(
                ProxyUtil.class.getClassLoader(),
                new Class[]{Star.class},
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                            if ("sing".equals(method.getName())){
                                System.out.println("准备唱歌，数钱");
                            } else if ("dance".equals(method.getName())) {
                                System.out.println("准备跳舞，数钱");
                            }
                        return method.invoke(bigStar,args);
                    }
                }
        );
        return star;
    }
}
